using System;
using MEA.AE_Data.Config;

namespace MEA.AE_Data
{
	public class EventLogEntry
	{
		public DateTime timestamp;

		public int eventID;

		private byte eventstate;

		public int entryCount;

		public string description;

		public ConfigData.e_ECUID ecu;

		public bool beginEvent;

		public bool timeStampInvalid;

		public EventLogEntry(ref DateTime timestamp, int eventID, byte eventstate, int entryCount, ref string description, ConfigData.e_ECUID ecu, bool timeStampInvalid)
		{
			this.timestamp = timestamp;
			this.eventID = eventID;
			this.eventstate = eventstate;
			this.entryCount = entryCount;
			this.description = description;
			this.ecu = ecu;
			this.timeStampInvalid = timeStampInvalid;
		}

		public string[] createRow()
		{
			string empty = string.Empty;
			string[] array = new string[5];
			if (timeStampInvalid)
			{
				array[0] = string.Format("{0} **", timestamp);
			}
			else
			{
				array[0] = string.Format("{0}", timestamp);
			}
			array[1] = string.Format("{0:X04}", eventID);
			array[2] = ConvertByteToBinaryString(eventstate);
			array[3] = string.Format("{0:X04}", entryCount);
			empty = string.Empty;
			if ((eventstate & 1) == 1)
			{
				empty += "Begin Event ";
				beginEvent = true;
			}
			else
			{
				empty += "End Event ";
				beginEvent = false;
			}
			if ((eventstate & 4) == 4)
			{
				empty = empty + ", RAM queue overflow! " + description;
			}
			empty = (((eventstate & 2) != 2) ? (empty + "(active) ") : (empty + "(passive) "));
			object obj = empty;
			empty = string.Concat(obj, "ECU ", ecu, ": ");
			array[4] = empty + description;
			return array;
		}

		private string ConvertByteToBinaryString(byte input)
		{
			string text = null;
			for (int num = 7; num >= 0; num--)
			{
				text = (((input & 0x80) != 128) ? (text + "0") : (text + "1"));
				input <<= 1;
			}
			return text;
		}
	}
}
